// ActionScript file
package com.app.business{
    import com.adobe.cairngorm.business.ServiceLocator;
    import com.app.factories.PengumumanFactory;
    import com.app.vo.DosenVO;
    import com.app.vo.MahasiswaVO;
    import com.app.vo.PengumumanVO;
    
    import mx.controls.Alert;
    import mx.rpc.AsyncToken;
    import mx.rpc.IResponder;
    import mx.rpc.events.FaultEvent;
    import mx.rpc.events.ResultEvent;
    import mx.rpc.http.HTTPService;
    

    public class PengumumanDelegate implements IResponder{
        protected var responder:IResponder;
        protected var service:HTTPService;
        protected var dosenVo:DosenVO;
        protected var pengumumanVo:PengumumanVO;
        protected var mahasiswaVo:MahasiswaVO;
        protected var Param:String;
        protected var Act:String;
        protected var Com:String;
        protected var rs:Array;
        
        public function PengumumanDelegate(responder:IResponder){
            this.service=ServiceLocator.getInstance().getHTTPService('services');
            this.responder=responder;
            this.rs=new Array();
        }  
        
        public function getListPengumumanByDosenId(pengVo:PengumumanVO):void{
            this.Param=pengVo.pengDosen;
            //Alert.show(this.Param);
            this.Act="getPengumuman";
            this.Com="pengumuman";
            var token:AsyncToken=service.send({com:Com,act:Act,params:Param});
            token.addResponder(this);
            this.pengumumanVo=pengVo;
        }
        public function getListPengumumanByMhsId(pengVo:PengumumanVO):void{
            this.Param=pengVo.pengMhsId;
            this.Act="getPengumumanByMhsId";
            this.Com="pengumuman";
            var token:AsyncToken=service.send({com:Com,act:Act,params:Param});
            token.addResponder(this);
            this.pengumumanVo=pengVo;
        }
        
        public function getPengumumanById(pengVo:PengumumanVO):void{
            this.Param=pengVo.pengMhsId;
            this.Act="getPengumumanById";
            this.Com="pengumuman";
            var token:AsyncToken=service.send({com:Com,act:Act,params:Param});
            token.addResponder(this);
            this.pengumumanVo=pengVo;
        }
        
        public function doAddPengumuman(pengVo:PengumumanVO):void{
            this.Param=pengVo.getAddParam();
            this.Act="doAddPengumuman";
            this.Com="pengumuman";
            var token:AsyncToken=service.send({com:Com,act:Act,params:Param});
            token.addResponder(this);
            this.pengumumanVo=pengVo;
        }
        public function doUpdatePengumuman(pengVo:PengumumanVO):void{
            this.Param=pengVo.getUpdateParam();
            this.Act="doUpdatePengumuman";
            this.Com="pengumuman";
            var token:AsyncToken=service.send({com:Com,act:Act,params:Param});
            token.addResponder(this);
            this.pengumumanVo=pengVo;
        }
        public function result(data:Object):void{
            var event:ResultEvent=ResultEvent(data);
            //Alert.show(event.result as String);
            if(event.result!='false'){
                if(this.Act=='getPengumuman'){
                    this.pengumumanVo=PengumumanFactory.buildListPengumumanByDosenId(event.result as String,this.pengumumanVo);
                    responder.result(this.pengumumanVo);
                }else if(this.Act=='getPengumumanByMhsId'){
                   this.pengumumanVo=PengumumanFactory.buildListPengumumanByMhsId(event.result as String,this.pengumumanVo);
                   responder.result(this.pengumumanVo);
                }else if(this.Act=='getPengumumanById'){
                   this.pengumumanVo=PengumumanFactory.buildPengumumanById(event.result as String,this.pengumumanVo);
                   responder.result(this.pengumumanVo);
                }else if(this.Act=='doAddPengumuman'){
                   responder.result(this.pengumumanVo);
                }else if(this.Act=='doUpdatePengumuman'){
                   responder.result(this.pengumumanVo);
                }
            }else{
                
            }
        }
        
        public function fault(info:Object):void{
            var err:FaultEvent= FaultEvent(info);
            
        }
    }
}